package com.yyz.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yyz.common.R;
import com.yyz.domain.DishFlavor;
import com.yyz.domain.Setmeal;
import com.yyz.domain.SetmealDish;
import com.yyz.dto.SetmealDto;
import com.yyz.service.SetMealService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author yyz
 * @create 2023-07-22 22:29
 */
@Slf4j
@RestController
@RequestMapping("/setmeal")
public class SetMealController {
    @Autowired
    private SetMealService setMealService;

    /**
     * 添加套餐
     *
     * @param setmealDto
     * @return
     */
    @PostMapping
    public R<String> insert(@RequestBody SetmealDto setmealDto) {
        log.info("{}", setmealDto);

        setMealService.insert(setmealDto);

        return R.success("添加成功！");
    }

    /**
     * 分页查询套餐
     *
     * @param page
     * @param pageSize
     * @param name
     * @return
     */
    @GetMapping("/page")
    public R page(Integer page, Integer pageSize, String name) {
        log.info("{},{},{}", page, pageSize, name);

        Page<SetmealDto> pageInfo = setMealService.page(page, pageSize, name);

        return R.success(pageInfo);
    }

    /**
     * 根据id页面回显
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public R<SetmealDto> selectById(@PathVariable Long id) {
        log.info("{}", id);

        SetmealDto setmealDto = setMealService.selectById(id);

        return R.success(setmealDto);

    }

    /**
     * 修改套餐
     *
     * @param setmealDto
     * @return
     */
    @PutMapping
    public R<String> update(@RequestBody SetmealDto setmealDto) {
        log.info("{}", setmealDto);

        setMealService.update(setmealDto);

        return R.success("修改成功！");
    }

    /**
     * 删除套餐
     *
     * @param ids
     * @return
     */
    @DeleteMapping
    public R<String> delete(Long[] ids) {
        log.info("{}", ids);

        setMealService.delete(ids);

        return R.success("删除成功！");
    }

    /**
     * 停售 启售
     *
     * @param statusId
     * @param ids
     * @return
     */
    @PostMapping("/status/{statusId}")
    public R<String> status(@PathVariable Integer statusId, Long[] ids) {
        log.info("{},{}", statusId, ids);

        setMealService.status(statusId, ids);

        return R.success("操作成功！");

    }


    /**
     * 根据条件查询套餐数据
     *
     * @param setmeal
     * @return
     */
    @GetMapping("/list")
    public R<List<Setmeal>> list(Setmeal setmeal) {
        log.info("{}",setmeal);

        List<Setmeal> setmeals = setMealService.list(setmeal);

        return R.success(setmeals);
    }
}
